package com.atguigu.springcloud.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Configuration
public class GateWayConfig {

    /**
     * 建议实用yml，更简洁
     * 配置了一个id为 route_name的路由规则
     * @param routeLocatorBuilder
     * @return
     */
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder) {
        RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
        // https://news.baidu.com/guonei
        routes.route("path_route_atguigu",
                r -> r.path("/guonei")
                         .uri("https://news.baidu.com/guonei")).build(); // 指定路由到这个位置

        return routes.build();
    }
}
